<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{$title}}</title>
    <link rel="stylesheet" href="./public/css/bootstrap.min.css">

</head>
<body>
    <script src="./public/js/jquery.min.js"></script>
    <script src="./public/js/bootstrap.min.js"></script>
    <h1>{{$title}}</h1>
    <div class="center-block mt20">
        <a href="./index.php?c=User&a=index" class="btn btn-info">首页</a>
        <a href="./index.php?c=User&a=add" class="btn btn-success">添加</a>
    </div>
    <hr>
    {{block name="main"}}
    <table class="table table-hover">
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Sex</th>
            <th>Age</th>
            <th>Province</th>
            <th class="col-md-2">操作</th>
        </tr>
        {{foreach $list as $v}}
        <tr>
            <td>{{$v['id']}}</td>
            <td>{{$v['name']}}</td>
            <td>
                {{if $v.sex == '0'}}女
                {{elseif $v.sex == '1'}}男
                {{else}}保密
                {{/if}}
            </td>
            <td>{{$v['age']}}</td>
            <td>{{$v['province']}}</td>
            <td>
                <a href="./index.php?c=User&a=edit&id={{$v['id']}}" class="btn btn-primary">编辑</a>
                <a onclick="del(this)" class="btn btn-danger">删除</a>
            </td>
        </tr>
        {{/foreach}}
    </table>
    {{/block}}

    <script>
        function del($m)
        {
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function(){
                if (xhr.readyState == 4 && xhr.status == 200){
                    var jsonStr = xhr.responseText;
                    var obj = JSON.parse(jsonStr);
                    // console.log(obj);
                    document.write(obj);
                }
            }
            xhr.open('get', './index.php?c=User&a=del', true);
            xhr.send();
        }
    </script>>
</body>
</html>